package 链表;

public class _206_反转链表 {
	/**
	 * Definition for singly-linked list. 输入: 1->2->3->4->5->NULL 输出:
	 * 5->4->3->2->1->NULL
	 */

	public ListNode reverseList(ListNode head) {
		if (head == null || head.next == null) {
			return head;
		}
		ListNode newHead = reverseList(head.next);
		head.next.next = head;
		head.next = null;
		return newHead;
	}

	public static ListNode reverseFun(ListNode head) {
		if (head == null || head.next == null) {
			return head;
		}
		ListNode newHead = null;
		while (head != null) {
			ListNode tmpNode = head.next;
			head.next = newHead;
			System.out.printf("newHead的地址:"+newHead+"\n");
			System.out.printf("head的地址:"+head+"\n");
			System.out.printf("head.next的地址:"+head.next+"\n");
			System.out.println("tmp的地址:"+tmpNode+"\n");
			newHead = head;
			System.out.printf("newHead的地址:"+newHead+"\n");
			System.out.printf("head的地址:"+head+"\n");
			System.out.printf("head.next的地址:"+head.next+"\n");
			System.out.println("tmp的地址:"+tmpNode+"\n");
			head = tmpNode;
			System.out.printf("newHead的地址:"+newHead+"\n");
			System.out.printf("head的地址:"+head+"\n");
			System.out.printf("head.next的地址:"+head.next+"\n");
			System.out.println("tmp的地址:"+tmpNode+"\n");
		}
		return newHead;
	}
	
	public static void main(String[] args) { 
		ListNode no1= new ListNode(1);
		ListNode no2= new ListNode(2);
		ListNode no3= new ListNode(3);
		no1.next = no2;
		no2.next = no3;
		no3.next = null;
		
	ListNode  nn = reverseFun(no1);
	
	System.out.println("1111");
	
	}
}
